#ifndef MAGNETIMAGE_SIMULATION
#define MAGNETIMAGE_SIMULATION

#pragma once
#include "ImageProcess.h"
#include "MagnetSystem.h"
#include "Particle.h"
#include "SetMagnetLocation.h"

#include <vector>
#include <time.h>
using namespace std;

class Simulation {

private:

	ImageProcess m_imageProcess;
	MagnetSystem m_magnetSystem;
	
	bool doneSimul;
	bool nowSimul;
	vector<Particle> m_particles;

	const char* fileName_option_range;
	const char* fileName_option_fmagnet;

	void LoadMagnetOption();
	void LoadRangeOption();
	void LoadRGBOpton();
	void LoadFMagnetRangeOption();
	

	int m_step;
	int m_step_detail;
	int m_max_step;
	char* m_fileName_particles;
	char* m_filename_temp;

	void SaveParticleToImage(const char* fileName);

	void SetFileName();
	const char* FileName_NextParticle();
	const char* FileName(const char* f);
	 


	void _test_simulation();
	void SaveMagnetToImage();


public:

	ParticleSystem* m_particleSystem;
	void *gui;

	Simulation() : m_step(0), m_step_detail(0), m_fileName_particles(NULL), m_filename_temp(NULL), m_particleSystem(NULL), 
		fileName_option_range("_option_range.bmp"), fileName_option_fmagnet("_option_fmagnet.bmp"), nowSimul(false) {

			system("echo off");

			SetFileName();
			m_filename_temp = new char[255];

			m_imageProcess.SetFileName_FillBlank( FileName("_fill_blank.bmp") );
			doneSimul = false;
	};
	~Simulation() {

		printf("Destructor Simulation\n");

		if (m_filename_temp) delete [] m_filename_temp;
		if (m_fileName_particles) delete [] m_fileName_particles;

		//if (m_particleSystem) delete m_particleSystem;

	};


	void LoadImage(const char* filename) {
		m_imageProcess.LoadImage(filename);
		m_imageProcess.SaveImage(FileName(filename));
	}

	void SaveImage(const char* filename){
		m_imageProcess.SaveImage(FileName(filename));
	}//void SaveImage(filename)


	void LoadOption();
	
	void SimulationBegin();
	void SimulationSingleStep();
	void SimulationDone();

	void Init(void *gui);
	void DoDisplay();
	
	void InitParticle();
	void DrawParticle();

	__forceinline bool isSimulationNow() { return nowSimul; };

	__forceinline int GetImageWidth() { return m_imageProcess.getImageWidth();}
	__forceinline int GetImageHeight() { return m_imageProcess.getImageHeight();}


};

#endif